package com.xgimi.open.skill.datamanager.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xgimi.commons.base.Result;
import com.xgimi.open.skill.datamanager.biz.common.Enum.ExceptionErrorCode;
import com.xgimi.open.skill.datamanager.biz.common.exception.BizException;
import com.xgimi.open.skill.datamanager.biz.service.SkillBizService;
import com.xgimi.open.skill.datamanager.service.api.SkillRpcService;
import com.xgimi.open.skill.datamanager.service.request.SkillReqDTO;
import com.xgimi.open.skill.datamanager.service.response.SkillRespDTO;
import com.xgimi.open.skill.datamanager.service.response.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author coderzpw.zhang
 * @version 1.0
 * @description 描述
 * @date 2023/3/3 14:24
 */
@Service
public class SkillRpcServiceImpl implements SkillRpcService {

    @Autowired
    private SkillBizService skillBizService;

    @Override
    public Result<Boolean> create(SkillReqDTO skillReqDTO) {
        Boolean ret = skillBizService.addSkill(skillReqDTO);
        return new Result<>(ret);
    }

    @Override
    public Result<PageResult<SkillRespDTO>> pageQuery(SkillReqDTO skillReqDTO) {
        PageResult<SkillRespDTO> pageQuery = skillBizService.pageQuery(skillReqDTO);
        return new Result<>(pageQuery);
    }

    @Override
    public Result<Boolean> update(SkillReqDTO skillReqDTO) {
        Boolean ret = skillBizService.updateSkill(skillReqDTO);
        return new Result<>(ret);
    }

    @Override
    public Result<Boolean> topSkill(SkillReqDTO skillReqDTO) {
        Boolean ret = skillBizService.topSkill(skillReqDTO);
        return new Result<>(ret);
    }

    @Override
    public Result<Boolean> cancelTop(SkillReqDTO skillReqDTO) {
        Boolean ret = skillBizService.cancelTop(skillReqDTO);
        return new Result<>(ret);
    }

    @Override
    public Result<Boolean> delete(SkillReqDTO skillReqDTO) {
        Boolean ret = skillBizService.deleteSkill(skillReqDTO);
        return new Result<>(ret);
    }

    @Override
    public Result<SkillRespDTO> queryById(Long id) {
        if (Objects.isNull(id)) {
            throw new BizException(ExceptionErrorCode.WORDSTOCK_ID_IS_NULL);
        }
        SkillRespDTO skillRespDTO = skillBizService.queryById(id);
        return new Result<>(skillRespDTO);
    }

    @Override
    public Result<List<SkillRespDTO>> getPublishedSkill() {
        List<SkillRespDTO> ret = skillBizService.getPublishedSkill();
        return new Result<>(ret);
    }

    @Override
    public Result<List<SkillRespDTO>> getAllSkill() {
        List<SkillRespDTO> ret = skillBizService.getAllSkill();
        return new Result<>(ret);
    }

    @Override
    public Result<Map<String, List<String>>> getOnlineAndTestSkillIds() {
        Map<String, List<String>> ret = skillBizService.getOnlineAndTestSkillIds();
        return new Result<>(ret);
    }
}
